package com.svpino.netflix;

import java.io.StringReader;

import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.InputSource;

public class Response {

	private final int code;
	private final String xml;

	public Response(int code, String xml) {
		this.code = code;
		this.xml = xml;
	}

	public String getXmlContent() {
		return this.xml;
	}

	public Element getXmlElement() throws Exception {
		DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
		StringReader reader = new StringReader(this.xml);
		InputSource inputSource = new InputSource(reader);
		Document document = documentBuilderFactory.newDocumentBuilder().parse(inputSource);
		reader.close();

		return document.getDocumentElement();
	}

	public int getCode() {
		return this.code;
	}

}
